package top.greatxiaozou.utils;

import top.greatxiaozou.dto.DtoUser;
import top.greatxiaozou.pojo.User;

public class UserUtils {
    public static final Integer year=2020;

    public static User changeUser(DtoUser user){
        User resultUser = new User();
        resultUser.setUsername(user.getUsername());
        resultUser.setPassword(user.getPassword());
        resultUser.setEmail(user.getEmail());
        resultUser.setTel(user.getTel());
        resultUser.setSex(user.getSex());
        resultUser.setSchool(user.getCollege());
        resultUser.setDescription(user.getDescription());
        resultUser.setName(user.getName());

        //根据出生年份算出年龄
        if (user.getBirth()!=null){
            String[] split = user.getBirth().split("-");
            resultUser.setAge(year-Integer.parseInt(split[0]));
        }else {
            resultUser.setAge(0);
        }

        return resultUser;
    }
}
